﻿using CurrentCostLibrary;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Communergy.Common;
namespace CurrentCostTest
{
    
    
    /// <summary>
    ///This is a test class for ReadingParserTest and is intended
    ///to contain all ReadingParserTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ReadingParserTest_Live
    {


        private TestContext testContextInstance;
        

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion




        /// <summary>
        ///A test for GetCurrentCostLiveReading
        ///</summary>
        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryLive_ReturnsCorrectReadingDateTime()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_REALTIME_XML;
            
            CurrentCostLiveReading actual;
            actual = ReadingParser.GetCurrentCostLiveReading(readingDate, inputFromCurrentCost, false);
            Assert.IsNotNull(actual);

            var expectedReadingDateTime = new DateTime(2009, 12, 7, 0, 13, 11);
            Assert.AreEqual(expectedReadingDateTime, actual.ReadingDateTime);
            
        }
        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryLive_ReturnsCorrectReadingDateTimeUseLocalTime()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_REALTIME_XML;
            
            CurrentCostLiveReading actual;
            actual = ReadingParser.GetCurrentCostLiveReading(readingDate, inputFromCurrentCost, true);
            Assert.IsNotNull(actual);

            var expectedReadingDateTime = new DateTime(2009, 12, 7, 0, 13, 11);
            Assert.AreNotEqual(expectedReadingDateTime, actual.ReadingDateTime);
            
        }
        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryLive_ReturnsCorrectSensorType()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_REALTIME_XML;

            var actual = ReadingParser.GetCurrentCostLiveReading(readingDate, inputFromCurrentCost, false);
            Assert.IsNotNull(actual);


            Assert.AreEqual(EnergyMonitorSensorType.Electricity, actual.SensorType);

        }

        /// <summary>
        ///A test for GetCurrentCostLiveReading
        ///</summary>
        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryLive_ReturnsCorrectWatts()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_REALTIME_XML;

            CurrentCostLiveReading actual;
            actual = ReadingParser.GetCurrentCostLiveReading(readingDate, inputFromCurrentCost, false);
            Assert.IsNotNull(actual);

            var expectedWatts = 145;
            Assert.AreEqual(expectedWatts, actual.AverageWatts);

        }

        /// <summary>
        ///A test for GetCurrentCostLiveReading
        ///</summary>
        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryLive_ReturnsCorrectSensor()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_REALTIME_XML;

            CurrentCostLiveReading actual;
            actual = ReadingParser.GetCurrentCostLiveReading(readingDate, inputFromCurrentCost, false);
            Assert.IsNotNull(actual);

            var expectedSensor = 1;//modified from the original reading to ensure default is not used
            Assert.AreEqual(expectedSensor, actual.SensorId);

        }

        /// <summary>
        ///A test for GetCurrentCostLiveReading
        ///</summary>
        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryLive_ReturnsCorrectNoApplicableData()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_DAILY_XML; //no live data

            CurrentCostLiveReading actual;
            actual = ReadingParser.GetCurrentCostLiveReading(readingDate, inputFromCurrentCost, false);
            Assert.IsNull(actual);  //will return null      

        }

    }
}
